﻿
using System.Configuration;
using M2B.GestionEntretiens.POCOS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;


namespace M2B.GestionEntretiens.DAL
{
    /// <summary>
    /// Cette Classe décrit une implémentation de unity of work
    /// </summary>
    /// <remarks>
    /// Informations de la classe : 
    /// <list type="bullet">
    /// <item name="authors">Auteur : M2B : Maher SAMMARI</item>
    /// <item name="creation date">Date de création : 01/04/2014</item>
    /// <item name="last modification">Date de dernière modification : 01/04/2014</item>
    /// </list>
    /// </remarks>
    [Serializable]
    public class UnitOfWork : IUnitOfWork
    {
        /// <summary>
        /// Gestion entretien context
        /// </summary>
        private GestionEntretiensContext _context;
        /// <summary>
        /// Candidats repository
        /// </summary>
        private CandidatsRepository _candidatsRepository;

        public string World {get { return "Hello Maher"; }}
        public CandidatsRepository CandidatsRepository
        {
            get
            {
                if (_candidatsRepository == null)
                {
                    _candidatsRepository = new CandidatsRepository(_context);
                }
                return _candidatsRepository;
            }
        }
        /// <summary>
        /// Entretiens repository
        /// </summary>
        private EntretiensRepository _entretiensRepository;
        public EntretiensRepository EntretiensRepository
        {
            get
            {
                if (_entretiensRepository == null)
                {
                    _entretiensRepository = new EntretiensRepository(_context);
                }
                return _entretiensRepository;
            }
        }
        /// <summary>
        /// Questions repository
        /// </summary>
        private QuestionsRepository _questionsRepository;
        public QuestionsRepository QuestionsRepository
        {
            get
            {
                if (_questionsRepository == null)
                {
                    _questionsRepository = new QuestionsRepository(_context);
                }
                return _questionsRepository;
            }
        }
        /// <summary>
        /// Propositions repository
        /// </summary>
        private PropositionsRepository _propositionsRepository;
        public PropositionsRepository PropositionsRepository
        {
            get
            {
                if (_propositionsRepository == null)
                {
                    _propositionsRepository = new PropositionsRepository(_context);
                }
                return _propositionsRepository;
            }
        }
        /// <summary>
        /// Tests repository
        /// </summary>
        private TestsRepository _testsRepository;
        public TestsRepository TestsRepository
        {
            get
            {
                if (_testsRepository == null)
                {
                    _testsRepository = new TestsRepository(_context);
                }
                return _testsRepository;
            }
        }
        /// <summary>
        /// Tests repository
        /// </summary>
        private ReferentielsRepository _referentielsRepository;
        public ReferentielsRepository ReferentielsRepository
        {
            get
            {
                if (_referentielsRepository == null)
                {
                    _referentielsRepository = new ReferentielsRepository(_context);
                }
                return _referentielsRepository;
            }
        }
        private TestQuestionsRepository _testQuestionsRepository;
        public TestQuestionsRepository TestQuestionsRepository
        {
            get
            {
                if (_testQuestionsRepository == null)
                {
                    _testQuestionsRepository = new TestQuestionsRepository(_context);
                }
                return _testQuestionsRepository;
            }
        }
        private ReponsesRepository _reponsensRepository;
        public ReponsesRepository ReponsensRepository
        {
            get
            {
                if (_reponsensRepository == null)
                {
                    _reponsensRepository = new ReponsesRepository(_context);
                }
                return _reponsensRepository;
            }
        }

        public UnitOfWork(string connectionString)
        {
            if(_context ==null)
            {
                _context = new GestionEntretiensContext(connectionString);
            }
        }

        
        #region Méthodes
        /// <summary>
        /// Commit du context
        /// </summary>
        public void Commit()
        {
            _context.Commit();
        }
        #endregion





        
    }
}
